//package com.llmops.demo;
//
//import com.llmops.core.listener.ChatModelLogListener;
//import dev.langchain4j.data.document.Document;
//import dev.langchain4j.data.document.DocumentParser;
//import dev.langchain4j.data.document.DocumentSplitter;
//import dev.langchain4j.data.document.parser.TextDocumentParser;
//import dev.langchain4j.data.document.splitter.DocumentSplitters;
//import dev.langchain4j.data.embedding.Embedding;
//import dev.langchain4j.data.segment.TextSegment;
//import dev.langchain4j.memory.ChatMemory;
//import dev.langchain4j.memory.chat.MessageWindowChatMemory;
//import dev.langchain4j.model.embedding.EmbeddingModel;
//import dev.langchain4j.model.openai.OpenAiChatModel;
//import dev.langchain4j.rag.content.retriever.ContentRetriever;
//import dev.langchain4j.rag.content.retriever.EmbeddingStoreContentRetriever;
//import dev.langchain4j.service.AiServices;
//import dev.langchain4j.store.embedding.EmbeddingStore;
//import dev.langchain4j.store.embedding.EmbeddingStoreIngestor;
//import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore;
//
//import java.util.List;
//
//import static dev.langchain4j.data.document.loader.FileSystemDocumentLoader.loadDocument;
//import static dev.langchain4j.data.document.loader.FileSystemDocumentLoader.loadDocuments;
//
//public class Native_RAG_Example {
//
//
//    interface Assistant {
//
//        String chat(String userMessage);
//    }
//
//    public static void main(String[] args) {
//        OpenAiChatModel chatModel = OpenAiChatModel.builder()
//                .baseUrl("https://api.deepseek.com/v1")
//                .apiKey("sk-0c3e6a9f9f7a4e63bb855290c544183c")
//                .modelName("deepseek-chat")
//                .listeners(List.of(new ChatModelLogListener()))
//                .build();
//
//        DocumentParser documentParser = new TextDocumentParser();
//        Document document = loadDocument("D:\\新建文件夹\\llmops\\src\\main\\java\\com\\llmops\\demo\\ragdata\\rag.txt", documentParser);
//        DocumentSplitter splitter = DocumentSplitters.recursive(300, 0);
//        List<TextSegment> segments = splitter.split(document);
//
//        EmbeddingModel embeddingModel = new BgeSmallEnV15QuantizedEmbeddingModel();
//        List<Embedding> embeddings = embeddingModel.embedAll(segments).content();
//
//        EmbeddingStore<TextSegment> embeddingStore = new InMemoryEmbeddingStore<>();
//        embeddingStore.addAll(embeddings, segments);
//
//        ContentRetriever contentRetriever = EmbeddingStoreContentRetriever.builder()
//                .embeddingStore(embeddingStore)
//                .embeddingModel(embeddingModel)
//                .maxResults(2) // on each interaction we will retrieve the 2 most relevant segments
//                .minScore(0.5) // we want to retrieve segments at least somewhat similar to user query
//                .build();
//
//        // Second, let's create an assistant that will have access to our documents
//        Assistant assistant = AiServices.builder(Assistant.class)
//                .chatModel(chatModel) // it should use OpenAI LLM
//                .chatMemory(MessageWindowChatMemory.withMaxMessages(10)) // it should remember 10 latest messages
//                .contentRetriever(contentRetriever) // it should have access to our documents
//                .build();
//
//        String answer = assistant.chat("LangChain4j是什么");
//        System.out.printf(answer);
//
//    }
//}
